

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>scitools.configdata &mdash; SciTools 0.9.0 documentation</title>
    
    <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../../',
        VERSION:     '0.9.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../../_static/jquery.js"></script>
    <script type="text/javascript" src="../../_static/underscore.js"></script>
    <script type="text/javascript" src="../../_static/doctools.js"></script>
    <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="top" title="SciTools 0.9.0 documentation" href="../../index.html" />
    <link rel="up" title="Module code" href="../index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for scitools.configdata</h1><div class="highlight"><pre>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">The Python module ConfigParser supports configuration files with the</span>
<span class="sd">usual Windows .INI file syntax. The present configdata module extends</span>
<span class="sd">the syntax of configuration files and provides a more easy-to-use</span>
<span class="sd">interface to such files. Variables can also be defined on the</span>
<span class="sd">command-line and through environment variables in addition to the</span>
<span class="sd">configuration file.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="n">__author__</span> <span class="o">=</span> <span class="s">&#39;Hans Petter Langtangen &lt;hpl@simula.no&gt;&#39;</span>

<span class="n">_configfile_description</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="s">User-friendly reading of configuration files with an extended</span>
<span class="s">Windows .INI syntax.</span>

<span class="s">The configuration file has sections in square brackets</span>
<span class="s">(e.g., [modes]) and option=value assignments in each section.</span>
<span class="s">The extended syntax offers type specification of the options.</span>
<span class="s">After the = sign the type appears in &lt;&gt; brackets followed by</span>
<span class="s">the value, e.g.::</span>

<span class="s">  [my section]</span>
<span class="s">  my first option = &lt;bool&gt; off   # can be on, off, yes, no, 1, 0</span>
<span class="s">  my second option = &lt;float&gt; 3.2</span>
<span class="s">  my third option = &lt;eval&gt; [1, 4, &#39;tmp.ps&#39;]  # a list as option value</span>
<span class="s">  my fourth option = MyClass     # no type specification here</span>
<span class="s">  my fifth option = &lt;eval&gt; StringFunction(&#39;sin(x)*cos(x)&#39;)</span>

<span class="s">The type must be bool, int, float, str, or eval.</span>
<span class="s">As an example, the &#39;my second option&#39; value will be a Python</span>
<span class="s">float object with the value 3.2 (without this type facility,</span>
<span class="s">the value would be the string &quot;3.2&quot;). In case of eval,</span>
<span class="s">the value is processed as eval(value) such that values can become</span>
<span class="s">lists, dictionaries, or other user-defined objects. In the latter</span>
<span class="s">case, the globals_ keyword must be set explicitly so that this</span>
<span class="s">function has access to the user&#39;s classes (eval(value, globals_)).</span>
<span class="s">For example, &#39;my fifth option&#39; will evaluate to StringFunction</span>
<span class="s">object, but this requires supply of globals_ with the user&#39;s</span>
<span class="s">imported modules (from StringFunction and math).</span>

<span class="s">There is also a syntax for marking options to be read-only, i.e.,</span>
<span class="s">these options are meant to be set in configuration files and</span>
<span class="s">not changed later in the program. Preceeding the type specification</span>
<span class="s">by an r or R indicates the read-only property, e.g.::</span>

<span class="s">  my first option = r&lt;bool&gt; off</span>

<span class="s">Options set in the configuration file can be overridden by</span>
<span class="s">associated environment variables whose names are on the form::</span>

<span class="s">  prefix_section_option</span>

<span class="s">For example, an option &#39;DEBUG&#39; in section &#39;globals&#39; can have</span>
<span class="s">an associated environment variable MYPACK_globals_DEBUG,</span>
<span class="s">if the prefix is MYPACK. The prefix is set in a special section</span>
<span class="s">called &#39;modes&#39; (see below).</span>

<span class="s">Options can also be overridden by command-line arguments. The</span>
<span class="s">command-line options have the same names as the associated</span>
<span class="s">environment variable names, but additionally prefixed by a double</span>
<span class="s">hyphen, e.g. --MYPACK_globals_DEBUG.</span>
<span class="s">The &#39;command line arguments&#39; option in the &#39;modes&#39; section</span>
<span class="s">must have a true value for this functionality to be active.</span>

<span class="s">Here is an example of the &#39;modes&#39; section::</span>

<span class="s">  [modes]</span>
<span class="s">  envir prefix = MATHPACK</span>
<span class="s">  command line arguments = yes</span>

<span class="s">If section or option names contain space(s), the corresponding</span>
<span class="s">environment variable name and command-line option have the space(s)</span>
<span class="s">replaced by underscore(s), e.g.::</span>

<span class="s">  MATHPACK_my_section_my_first_option</span>
<span class="s">  --MATHPACK_my_section_my_first_option</span>

<span class="s">Such command-line options and values are removed from sys.argv after</span>
<span class="s">being read.</span>

<span class="s">A convenient feature of configuration files is that variable interpolation</span>
<span class="s">is possible(see the documentation of ConfigParser in the Python</span>
<span class="s">Library Reference). Here is an example::</span>

<span class="s">  [DEFAULT]</span>
<span class="s">  path = /my/home/dir/</span>

<span class="s">  [storage]</span>
<span class="s">  datapath = </span><span class="si">%(path)s</span><span class="s">/data</span>
<span class="s">  input = </span><span class="si">%(path)s</span><span class="s">/</span><span class="si">%(datapath)s</span><span class="s">/input</span>

<span class="s">One can also provide variables for being used in variable interpolation</span>
<span class="s">throught the default_dict4intpl argument to this function.</span>

<span class="s">A configuration file is searched for and read in as follows</span>
<span class="s">(in the listed order):</span>

<span class="s">  1. basename.cfg in the default_file_location directory,</span>
<span class="s">  2. basename.cfg files for each directory in other_locations list,</span>
<span class="s">  4. .basename.cfg in the user&#39;s home directory,</span>
<span class="s">  3. .basename.cfg in the directory where the main script is running.</span>

<span class="s">This priority implies that the a config file in the current working</span>
<span class="s">directory will override any user or any other system settings.</span>
<span class="s">&quot;&quot;&quot;</span>
<span class="n">__doc__</span> <span class="o">+=</span> <span class="n">_configfile_description</span>


<span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span>

<span class="n">VALUE</span><span class="o">=</span><span class="mi">0</span><span class="p">;</span> <span class="n">STR2TYPE</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span> <span class="n">READONLY</span><span class="o">=</span><span class="mi">2</span>  <span class="c"># logical names for list indices</span>

<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;tobool&#39;</span><span class="p">,</span> <span class="s">&#39;config_parser_frontend&#39;</span><span class="p">,</span> <span class="s">&#39;values_only&#39;</span><span class="p">,</span> <span class="s">&#39;dict2xml&#39;</span><span class="p">]</span>

<div class="viewcode-block" id="tobool"><a class="viewcode-back" href="../../configdata.html#scitools.configdata.tobool">[docs]</a><span class="k">def</span> <span class="nf">tobool</span><span class="p">(</span><span class="n">value</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Convert value (1, &#39;1&#39;, 0, &#39;0&#39;, &#39;yes&#39;, &#39;true&#39;, &#39;no&#39;, &#39;false&#39;, &#39;on&#39;,</span>
<span class="sd">    &#39;off&#39;, or any integer) to a bool object. The string values are</span>
<span class="sd">    treated in a case-insensitive way.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">trues</span>  <span class="o">=</span> <span class="s">&quot;1&quot;</span><span class="p">,</span> <span class="s">&quot;yes&quot;</span><span class="p">,</span> <span class="s">&quot;Yes&quot;</span><span class="p">,</span> <span class="s">&quot;YES&quot;</span><span class="p">,</span> <span class="s">&quot;true&quot;</span><span class="p">,</span>  <span class="s">&quot;True&quot;</span><span class="p">,</span>  <span class="s">&quot;on&quot;</span><span class="p">,</span>  <span class="mi">1</span>
    <span class="n">falses</span> <span class="o">=</span> <span class="s">&quot;0&quot;</span><span class="p">,</span> <span class="s">&quot;no&quot;</span><span class="p">,</span>  <span class="s">&quot;No&quot;</span><span class="p">,</span>  <span class="s">&quot;NO&quot;</span><span class="p">,</span>  <span class="s">&quot;false&quot;</span><span class="p">,</span> <span class="s">&quot;False&quot;</span><span class="p">,</span> <span class="s">&quot;off&quot;</span><span class="p">,</span> <span class="mi">0</span>
    <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span> <span class="c"># case-insensitive check</span>

    <span class="k">if</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">trues</span><span class="p">:</span>
        <span class="n">value</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="k">elif</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">falses</span><span class="p">:</span>
        <span class="n">value</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
        <span class="k">return</span> <span class="nb">bool</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;the value </span><span class="si">%s</span><span class="s"> cannot be converted to bool&#39;</span> <span class="o">%</span> <span class="n">value</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">value</span>
</div>
<span class="k">def</span> <span class="nf">_option_interpolation_error</span><span class="p">(</span><span class="n">files</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span> <span class="n">value</span><span class="p">,</span>
                                <span class="n">str2type</span><span class="p">,</span> <span class="n">read_only</span><span class="p">):</span>
    <span class="k">if</span> <span class="n">read_only</span><span class="p">:</span>
        <span class="n">r</span> <span class="o">=</span> <span class="s">&#39;r&#39;</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">r</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;configuration file error in </span><span class="si">%s</span><span class="se">\n</span><span class="s">&#39;</span>\
                     <span class="s">&#39;section [</span><span class="si">%s</span><span class="s">], option &quot;</span><span class="si">%s</span><span class="s">&quot;: do not use </span><span class="si">%s</span><span class="s">&lt;</span><span class="si">%s</span><span class="s">&gt;</span><span class="se">\n</span><span class="s">&#39;</span>\
                     <span class="s">&#39;specifications in options that are to be &#39;</span>\
                     <span class="s">&#39;substituted in other options: </span><span class="si">%s</span><span class="s">&#39;</span> <span class="o">%</span> \
                     <span class="p">(</span><span class="n">files</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span> <span class="n">r</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span> <span class="n">value</span><span class="p">))</span>

<span class="k">def</span> <span class="nf">load_config_file</span><span class="p">(</span><span class="n">name</span><span class="p">,</span>
                     <span class="n">default_file_location</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
                     <span class="n">extension</span><span class="o">=</span><span class="s">&#39;.cfg&#39;</span><span class="p">,</span>
                     <span class="n">other_locations</span><span class="o">=</span><span class="p">[],</span>
                     <span class="n">case_sensitive_options</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
                     <span class="n">default_dict4intpl</span><span class="o">=</span><span class="p">{}):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Load a config file with the format implied by the ConfigParser</span>
<span class="sd">    module (Windows .INI files).</span>

<span class="sd">    A config file is searched for and read in as follows (in the listed order):</span>

<span class="sd">      1. name.cfg in the default_file_location directory,</span>
<span class="sd">      2. name.cfg files for each directory in other_locations list,</span>
<span class="sd">      4. .name.cfg in the user&#39;s home directory,</span>
<span class="sd">      3. .name.cfg in the directory where the main script is running.</span>

<span class="sd">    This priority implies that the a config file in the current working</span>
<span class="sd">    directory will override any user or any other system settings.</span>

<span class="sd">    @param name: name stem of config file, e.g., &quot;mytools&quot; (then</span>
<span class="sd">    &quot;mytools.cfg&quot; is the complete name of the config file if extension</span>
<span class="sd">    is &quot;.cfg&quot;).</span>
<span class="sd">    @param default_file_location: name of directory containing a</span>
<span class="sd">    file name.extension with default values (to be read before other</span>
<span class="sd">    configuration files). If None, the directory where this module</span>
<span class="sd">    (configdata) resides will be tried. A typical value for a system</span>
<span class="sd">    configuration file is os.path.dirname(__file__) (i.e., the same</span>
<span class="sd">    directory as the calling module in the package).</span>
<span class="sd">    @param extension: extension of config file (name.extension is the</span>
<span class="sd">    complete name).</span>
<span class="sd">    @param other_locations: list of directories with name.extension files.</span>
<span class="sd">    @param default_dict4intpl: dictionary with variable names and values</span>
<span class="sd">    for use in variable interpolation in the configuration file.</span>
<span class="sd">    @param case_sensitive_options: by default, the options in configuration</span>
<span class="sd">    files are transformed to lower case, so setting this parameter to True,</span>
<span class="sd">    makes options case sensitive.</span>
<span class="sd">    @param default_dict4intpl: dictionary with variable names and values</span>
<span class="sd">    for use in variable interpolation in the configuration file.</span>
<span class="sd">    @return: a SafeConfigParser object and a list of filenames of the</span>
<span class="sd">    files that were read to set parameters in the SafeConfigParser object.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">ConfigParser</span>
    <span class="n">config</span> <span class="o">=</span> <span class="n">ConfigParser</span><span class="o">.</span><span class="n">SafeConfigParser</span><span class="p">(</span><span class="n">default_dict4intpl</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">case_sensitive_options</span><span class="p">:</span>
        <span class="n">config</span><span class="o">.</span><span class="n">optionxform</span> <span class="o">=</span> <span class="nb">str</span>

    <span class="k">if</span> <span class="n">default_file_location</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="c"># try the directory where this module resides:</span>
        <span class="n">default_file_location</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">dirname</span><span class="p">(</span><span class="n">__file__</span><span class="p">)</span>

    <span class="n">default_config_file</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">default_file_location</span><span class="p">,</span>
                                       <span class="s">&#39;</span><span class="si">%s%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">extension</span><span class="p">))</span>
    <span class="n">read_files</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">isfile</span><span class="p">(</span><span class="n">default_config_file</span><span class="p">):</span>
        <span class="n">config</span><span class="o">.</span><span class="n">readfp</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="n">default_config_file</span><span class="p">,</span> <span class="s">&#39;r&#39;</span><span class="p">))</span>
        <span class="n">read_files</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">default_config_file</span><span class="p">)</span>
    <span class="c">#else:</span>
    <span class="c">#    print &#39;No data in&#39;, default_config_file</span>
    <span class="n">dirs</span> <span class="o">=</span> <span class="n">other_locations</span>
    <span class="n">candidate_files</span> <span class="o">=</span> <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">loc</span><span class="p">,</span> <span class="s">&#39;.</span><span class="si">%s%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">extension</span><span class="p">))</span> \
                       <span class="k">for</span> <span class="n">loc</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">]</span> <span class="o">+</span> \
                       <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">expanduser</span><span class="p">(</span><span class="s">&#39;~/.</span><span class="si">%s%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">extension</span><span class="p">))]</span> <span class="o">+</span> \
                       <span class="p">[</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">curdir</span><span class="p">,</span> <span class="s">&#39;.</span><span class="si">%s%s</span><span class="s">&#39;</span> <span class="o">%</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">extension</span><span class="p">))]</span>
    <span class="c">#print candidate_files</span>
    <span class="n">files</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="n">candidate_files</span><span class="p">)</span>
    <span class="n">read_files</span> <span class="o">=</span> <span class="n">read_files</span> <span class="o">+</span> <span class="n">files</span>
    <span class="k">return</span> <span class="n">config</span><span class="p">,</span> <span class="n">read_files</span>


<div class="viewcode-block" id="config_parser_frontend"><a class="viewcode-back" href="../../configdata.html#scitools.configdata.config_parser_frontend">[docs]</a><span class="k">def</span> <span class="nf">config_parser_frontend</span><span class="p">(</span><span class="n">basename</span><span class="p">,</span>
                           <span class="n">default_file_location</span><span class="p">,</span>
                           <span class="n">extension</span><span class="o">=</span><span class="s">&#39;.cfg&#39;</span><span class="p">,</span>
                           <span class="n">other_locations</span><span class="o">=</span><span class="p">[],</span>
                           <span class="n">default_dict4intpl</span><span class="o">=</span><span class="p">{},</span>
                           <span class="n">globals_</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    =======================  =============================================</span>
<span class="sd">    Parameter                  Description</span>
<span class="sd">    =======================  =============================================</span>
<span class="sd">    basename                 name stem of config file, e.g., &quot;mytools&quot;</span>
<span class="sd">                             (then &quot;mytools.cfg&quot; is the complete name</span>
<span class="sd">                             of the config file if extension is &quot;.cfg&quot;).</span>
<span class="sd">    extension                extension of config file (basename.extension</span>
<span class="sd">                             is the complete name)</span>
<span class="sd">    default_file_location    name of directory containing a file</span>
<span class="sd">                             basename.extension with default values</span>
<span class="sd">                             (to be read before other configuration files).</span>
<span class="sd">    other_locations          list of directories with basename.extension</span>
<span class="sd">                             files</span>
<span class="sd">    default_dict4intp        dictionary with variable names and values</span>
<span class="sd">                             for use in variable interpolation in the</span>
<span class="sd">                             configuration file</span>
<span class="sd">    globals_                 dictionary of global names that are used when</span>
<span class="sd">                             running eval on option values. If None, the</span>
<span class="sd">                             global names in this module are used</span>
<span class="sd">    return                   a dictionary with [section][option] keys and</span>
<span class="sd">                             a values of the form of a three-element list</span>
<span class="sd">                             holding the option value, the string to right</span>
<span class="sd">                             type conversion function (callable), and a bool</span>
<span class="sd">                             indicator if the value is read-only.</span>
<span class="sd">                             The other returned object is a list of filenames</span>
<span class="sd">                             of the configuration files that were loaded</span>
<span class="sd">    =======================  =============================================</span>

<span class="sd">Regarding default_file_location, a None value indicates the directory</span>
<span class="sd">where this module (configdata) resides will be tried. A typical value</span>
<span class="sd">for a system configuration file is ``os.path.dirname(__file__)`` (i.e.,</span>
<span class="sd">the same directory as the calling module in the package).</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">globals_</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">globals_</span> <span class="o">=</span> <span class="nb">globals</span><span class="p">()</span>

    <span class="c"># load configuration file:</span>
    <span class="n">config</span><span class="p">,</span> <span class="n">files</span> <span class="o">=</span> \
            <span class="n">load_config_file</span><span class="p">(</span><span class="n">basename</span><span class="p">,</span>
                             <span class="n">default_file_location</span><span class="o">=</span><span class="n">default_file_location</span><span class="p">,</span>
                             <span class="n">extension</span><span class="o">=</span><span class="n">extension</span><span class="p">,</span>
                             <span class="n">other_locations</span><span class="o">=</span><span class="n">other_locations</span><span class="p">,</span>
                             <span class="n">case_sensitive_options</span><span class="o">=</span><span class="bp">True</span><span class="p">,</span>
                             <span class="n">default_dict4intpl</span><span class="o">=</span><span class="n">default_dict4intpl</span><span class="p">)</span>

    <span class="c"># dictionary with [section][option] keys and values as a</span>
    <span class="c"># list [value, str2type, readonly]</span>
    <span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>

    <span class="c"># read &#39;modes&#39; section first to see if settings in the config</span>
    <span class="c"># file can be overridden by environment variables and/or</span>
    <span class="c"># command-line options:</span>
    <span class="n">envir_prefix</span> <span class="o">=</span> <span class="s">&#39;&#39;</span>
    <span class="n">cml_arg</span> <span class="o">=</span> <span class="bp">False</span>
    <span class="n">section</span> <span class="o">=</span> <span class="s">&#39;modes&#39;</span>
    <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">has_section</span><span class="p">(</span><span class="n">section</span><span class="p">):</span>
        <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">option</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;envir prefix&#39;</span><span class="p">,</span> <span class="s">&#39;environment variable prefix&#39;</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">has_option</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">):</span>
                <span class="n">envir_prefix</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">)</span>
                <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">envir_prefix</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="bp">True</span><span class="p">]</span>
            <span class="k">break</span>
        <span class="k">for</span> <span class="n">option</span> <span class="ow">in</span> <span class="p">(</span><span class="s">&#39;command line arguments&#39;</span><span class="p">,):</span>
            <span class="k">if</span> <span class="n">config</span><span class="o">.</span><span class="n">has_option</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">):</span>
                <span class="n">cml_arg</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">getboolean</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">)</span>
            <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">cml_arg</span><span class="p">,</span> <span class="nb">bool</span><span class="p">,</span> <span class="bp">True</span><span class="p">]</span>

    <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">sections</span><span class="p">():</span>
        <span class="k">if</span> <span class="n">section</span> <span class="o">==</span> <span class="s">&#39;modes&#39;</span><span class="p">:</span>   <span class="c"># &#39;modes&#39; is already processed above</span>
            <span class="k">continue</span>
        <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">option</span> <span class="ow">in</span> <span class="n">config</span><span class="o">.</span><span class="n">options</span><span class="p">(</span><span class="n">section</span><span class="p">):</span>
            <span class="n">value</span> <span class="o">=</span> <span class="n">config</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">)</span>
            <span class="c"># check if value has the syntax &quot;&lt;str2type&gt; expression&quot;</span>
            <span class="n">str2type</span> <span class="o">=</span> <span class="bp">None</span>
            <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;&lt;&#39;</span><span class="p">):</span>
                <span class="n">read_only</span> <span class="o">=</span> <span class="bp">False</span>
                <span class="n">gt</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;&gt;&#39;</span><span class="p">)</span>
                <span class="n">str2type</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="n">gt</span><span class="p">]</span>
                <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="n">gt</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="c"># variable interpolation are destroyed by &lt;str&gt; specs;</span>
                <span class="c"># could process all values without %(...)s first and</span>
                <span class="c"># then remove all &lt;type&gt; specifications to make</span>
                <span class="c"># variable interpolation correct</span>
                <span class="k">if</span> <span class="s">&#39;&lt;</span><span class="si">%s</span><span class="s">&gt;&#39;</span> <span class="o">%</span> <span class="n">str2type</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
                    <span class="n">_option_interpolation_error</span><span class="p">(</span><span class="n">files</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span>
                                                <span class="n">value</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span> <span class="bp">False</span><span class="p">)</span>
            <span class="k">elif</span> <span class="n">value</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">&#39;r&lt;&#39;</span><span class="p">):</span>
                <span class="n">read_only</span> <span class="o">=</span> <span class="bp">True</span>
                <span class="n">gt</span> <span class="o">=</span> <span class="n">value</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s">&#39;&gt;&#39;</span><span class="p">)</span>
                <span class="n">str2type</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="n">gt</span><span class="p">]</span>
                <span class="n">value</span> <span class="o">=</span> <span class="n">value</span><span class="p">[</span><span class="n">gt</span><span class="o">+</span><span class="mi">1</span><span class="p">:]</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span>
                <span class="c"># set this option in the config file so that</span>
                <span class="c"># variable interpolation may work:</span>
                <span class="n">config</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
                <span class="k">if</span> <span class="s">&#39;r&lt;</span><span class="si">%s</span><span class="s">&gt;&#39;</span> <span class="o">%</span> <span class="n">str2type</span> <span class="ow">in</span> <span class="n">value</span><span class="p">:</span>
                    <span class="n">_option_interpolation_error</span><span class="p">(</span><span class="n">files</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span>
                                                <span class="n">value</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">str2type</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">if</span> <span class="n">str2type</span> <span class="o">==</span> <span class="s">&#39;bool&#39;</span> <span class="ow">or</span> <span class="n">str2type</span> <span class="o">==</span> <span class="s">&#39;tobool&#39;</span><span class="p">:</span>
                    <span class="n">value</span> <span class="o">=</span> <span class="n">tobool</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">,</span> <span class="n">tobool</span><span class="p">,</span> <span class="n">read_only</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="s">&#39;float&#39;</span><span class="p">:</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">float</span><span class="p">(</span><span class="n">value</span><span class="p">),</span> <span class="nb">float</span><span class="p">,</span> <span class="n">read_only</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="s">&#39;int&#39;</span><span class="p">:</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">value</span><span class="p">),</span> <span class="nb">int</span><span class="p">,</span> <span class="n">read_only</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="s">&#39;str&#39;</span><span class="p">:</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="nb">str</span><span class="p">(</span><span class="n">value</span><span class="p">),</span> <span class="nb">str</span><span class="p">,</span> <span class="n">read_only</span><span class="p">]</span>
                <span class="k">elif</span> <span class="n">str2type</span> <span class="o">==</span> <span class="s">&#39;eval&#39;</span><span class="p">:</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> \
                                   <span class="p">[</span><span class="nb">eval</span><span class="p">(</span><span class="n">value</span><span class="p">,</span> <span class="n">globals_</span><span class="p">),</span> <span class="nb">eval</span><span class="p">,</span> <span class="n">read_only</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="c"># no type specification, value becomes a string:</span>
                <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">value</span><span class="p">,</span> <span class="nb">str</span><span class="p">,</span> <span class="bp">False</span><span class="p">]</span>

            <span class="c"># override file value by environment variable or</span>
            <span class="c"># command-line argument?</span>

            <span class="n">envir_var_name</span> <span class="o">=</span> <span class="n">envir_prefix</span> <span class="o">+</span> <span class="s">&#39;_&#39;</span> <span class="o">+</span> <span class="n">section</span> <span class="o">+</span> <span class="s">&#39;_&#39;</span> <span class="o">+</span> <span class="n">option</span>
            <span class="n">envir_var_name</span> <span class="o">=</span> <span class="n">envir_var_name</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">&#39; &#39;</span><span class="p">,</span> <span class="s">&#39;_&#39;</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">envir_prefix</span><span class="p">:</span>
                <span class="c"># override by environment variable:</span>
                <span class="k">if</span> <span class="n">envir_var_name</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">:</span>
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">][</span><span class="n">VALUE</span><span class="p">]</span> <span class="o">=</span> \
                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">][</span><span class="n">STR2TYPE</span><span class="p">](</span><span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="n">envir_var_name</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">cml_arg</span><span class="p">:</span>
                <span class="n">cml_option</span> <span class="o">=</span> <span class="s">&#39;--&#39;</span> <span class="o">+</span> <span class="n">envir_var_name</span>
                <span class="k">if</span> <span class="n">cml_option</span> <span class="ow">in</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">:</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="n">i</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="n">cml_option</span><span class="p">)</span>
                        <span class="n">v</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
                        <span class="c"># remove config option and value from sys.argv:</span>
                        <span class="k">del</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>  <span class="c"># option</span>
                        <span class="k">del</span> <span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>  <span class="c"># value</span>
                    <span class="k">except</span> <span class="ne">IndexError</span><span class="p">:</span>
                        <span class="k">print</span> <span class="s">&quot;&quot;&quot;</span>
<span class="si">%s</span><span class="s"> command-line option must be followed by a value!</span>
<span class="s">&quot;&quot;&quot;</span> <span class="o">%</span> <span class="n">cml_option</span>
                        <span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>

                    <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">][</span><span class="n">VALUE</span><span class="p">]</span> <span class="o">=</span> \
                           <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">][</span><span class="n">STR2TYPE</span><span class="p">](</span><span class="n">v</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">data</span><span class="p">,</span> <span class="n">files</span>
</div>
<span class="n">config_parser_frontend</span><span class="o">.</span><span class="n">__doc__</span> <span class="o">=</span> <span class="n">_configfile_description</span>


<div class="viewcode-block" id="dict2xml"><a class="viewcode-back" href="../../configdata.html#scitools.configdata.dict2xml">[docs]</a><span class="k">def</span> <span class="nf">dict2xml</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">syntax</span><span class="o">=</span><span class="s">&#39;gnosis&#39;</span><span class="p">,</span>
             <span class="n">section_name</span><span class="o">=</span><span class="s">&#39;section&#39;</span><span class="p">,</span> <span class="n">option_name</span><span class="o">=</span><span class="s">&#39;option&#39;</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Takes a data dictionary, as output from the config_parser_frontend</span>
<span class="sd">    function, and stores in a string with XML syntax.</span>

<span class="sd">    @param data: dictionary of the form data[section][option] = (v, s2t, ro),</span>
<span class="sd">    where v is a Python object (value), s2t is a callable, and ro is</span>
<span class="sd">    a bool.</span>
<span class="sd">    @param syntax: &#39;gnosis&#39; gives gnosis XML_Pickler syntax, &#39;plain&#39; gives</span>
<span class="sd">    a simpler to read syntax.</span>
<span class="sd">    @param section_name: the name of sections (highest key level) in the</span>
<span class="sd">    data dictionary to be used as XML tagname. (&quot;section&quot; and &quot;option&quot; are</span>
<span class="sd">    the terms used by the Python ConfigParser tool.)</span>
<span class="sd">    @param option_name: the name of options (lowest key level) in the</span>
<span class="sd">    data dictionary to be used as XML tagname.</span>
<span class="sd">    @return: a string with XML syntax.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">syntax</span> <span class="o">==</span> <span class="s">&#39;gnosis&#39;</span><span class="p">:</span>
        <span class="kn">from</span> <span class="nn">gnosis.xml.pickle</span> <span class="kn">import</span> <span class="n">XML_Pickler</span>
        <span class="k">class</span> <span class="nc">ClassWrapper</span><span class="p">(</span><span class="n">XML_Pickler</span><span class="p">):</span>
            <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>

        <span class="n">datawrap</span> <span class="o">=</span> <span class="n">ClassWrapper</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">datawrap</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c"># simpler XML syntax:</span>
        <span class="kn">from</span> <span class="nn">errorcheck</span> <span class="kn">import</span> <span class="n">get_type</span>
        <span class="n">s</span> <span class="o">=</span> <span class="s">&#39;&lt;data dictionary&gt;</span><span class="se">\n</span><span class="s">&#39;</span>
        <span class="n">indent</span> <span class="o">=</span> <span class="mi">4</span>
        <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
            <span class="n">current_indent</span> <span class="o">=</span> <span class="s">&#39; &#39;</span><span class="o">*</span><span class="n">indent</span>
            <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">&lt;</span><span class="si">%s</span><span class="s">&gt;</span><span class="si">%s</span><span class="s">&lt;/</span><span class="si">%s</span><span class="s">&gt;</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> \
                 <span class="p">(</span><span class="n">current_indent</span><span class="p">,</span> <span class="n">section_name</span><span class="p">,</span> <span class="n">section</span><span class="p">,</span> <span class="n">section_name</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">option</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">]:</span>
                <span class="n">value</span><span class="p">,</span> <span class="n">str2type</span><span class="p">,</span> <span class="n">read_only</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span>
                <span class="n">current_indent</span> <span class="o">=</span> <span class="s">&#39; &#39;</span><span class="o">*</span><span class="n">indent</span><span class="o">*</span><span class="mi">2</span>
                <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">&lt;</span><span class="si">%s</span><span class="s">&gt;</span><span class="si">%s</span><span class="s">&lt;/</span><span class="si">%s</span><span class="s">&gt;</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> \
                     <span class="p">(</span><span class="n">current_indent</span><span class="p">,</span> <span class="n">option_name</span><span class="p">,</span> <span class="n">option</span><span class="p">,</span> <span class="n">option_name</span><span class="p">)</span>
                <span class="n">current_indent</span> <span class="o">=</span> <span class="s">&#39; &#39;</span><span class="o">*</span><span class="n">indent</span><span class="o">*</span><span class="mi">3</span>
                <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;</span><span class="si">%s</span><span class="s">&lt;value type=&quot;</span><span class="si">%s</span><span class="s">&quot; readonly=&quot;</span><span class="si">%s</span><span class="s">&quot;&gt;</span><span class="si">%s</span><span class="s">&lt;/value&gt;</span><span class="se">\n</span><span class="s">&#39;</span> <span class="o">%</span> \
                <span class="p">(</span><span class="n">current_indent</span><span class="p">,</span> <span class="n">get_type</span><span class="p">(</span><span class="n">value</span><span class="p">),</span> <span class="n">read_only</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
        <span class="n">s</span> <span class="o">+=</span> <span class="s">&#39;&lt;/data dictionary&gt;</span><span class="se">\n</span><span class="s">&#39;</span>
        <span class="k">return</span> <span class="n">s</span>
</div>
<div class="viewcode-block" id="values_only"><a class="viewcode-back" href="../../configdata.html#scitools.configdata.values_only">[docs]</a><span class="k">def</span> <span class="nf">values_only</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Strip the three-tuple (value, str2type, readonly) in the dictionary</span>
<span class="sd">    returned from config_parser_frontend to a dictionary with option</span>
<span class="sd">    values only.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="kn">import</span> <span class="nn">copy</span>
    <span class="n">rdata</span> <span class="o">=</span> <span class="n">copy</span><span class="o">.</span><span class="n">deepcopy</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>   <span class="c"># data.copy() is only shallow copy!</span>
    <span class="k">for</span> <span class="n">section</span> <span class="ow">in</span> <span class="n">rdata</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">option</span> <span class="ow">in</span> <span class="n">rdata</span><span class="p">[</span><span class="n">section</span><span class="p">]:</span>
            <span class="n">rdata</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="n">rdata</span><span class="p">[</span><span class="n">section</span><span class="p">][</span><span class="n">option</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">rdata</span>
</div>
<span class="k">def</span> <span class="nf">_test</span><span class="p">():</span>
    <span class="n">configdata</span> <span class="o">=</span> <span class="s">&quot;&quot;&quot;</span>
<span class="s">[modes]</span>
<span class="s">; Enable setting variables by environment variables with</span>
<span class="s">; prefix_variablename, e.g., MyProject_section_option</span>
<span class="s">envir prefix = MyProject</span>

<span class="s">; Enable reading from command line through --MyProject_section_option</span>
<span class="s">command line arguments = on</span>

<span class="s">[global directories]</span>
<span class="s">projects = r&lt;str&gt; projects</span>
<span class="s">templates = r&lt;str&gt; templates</span>
<span class="s">project template = r&lt;str&gt; </span><span class="si">%(templates)s</span><span class="s">/project</span>

<span class="s">[file extensions]</span>
<span class="s">project = .igm</span>
<span class="s">report = r&lt;eval&gt; [&#39;.html&#39;, &#39;.htm&#39;]</span>

<span class="s">[debugging]</span>
<span class="s">DEBUG = &lt;int&gt; 0</span>
<span class="s">VERBOSE = &lt;int&gt; 1</span>

<span class="s">[system messages]</span>
<span class="s">run.warning.text = &lt;str&gt;</span>
<span class="s">    Not all parent worksteps are checked in.</span>
<span class="s">    Since the results must be reproducible, only those that are checked in will</span>
<span class="s">    be used as data sources.</span>

<span class="s">unknowndir.overwrite.title = &lt;str&gt; Overwrite selected directory?</span>

<span class="s">[data files]</span>
<span class="s">data glob = &lt;str&gt; *_simulation_results.*</span>
<span class="s">&quot;&quot;&quot;</span>
    <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s">&#39;tmp.cfg&#39;</span><span class="p">,</span> <span class="s">&#39;w&#39;</span><span class="p">);</span> <span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">configdata</span><span class="p">);</span> <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="n">data</span><span class="p">,</span> <span class="n">files</span> <span class="o">=</span> <span class="n">config_parser_frontend</span><span class="p">(</span><span class="s">&#39;tmp&#39;</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">curdir</span><span class="p">)</span>
    <span class="kn">import</span> <span class="nn">pprint</span>
    <span class="n">pprint</span><span class="o">.</span><span class="n">pprint</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">data_values</span> <span class="o">=</span> <span class="n">values_only</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="n">pprint</span><span class="o">.</span><span class="n">pprint</span><span class="p">(</span><span class="n">data_values</span><span class="p">)</span>
    <span class="k">print</span> <span class="n">dict2xml</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="k">print</span> <span class="n">dict2xml</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">syntax</span><span class="o">=</span><span class="s">&#39;plain&#39;</span><span class="p">)</span>

<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&#39;__main__&#39;</span><span class="p">:</span>
    <span class="n">_test</span><span class="p">()</span>
</pre></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/scitools_logo.jpg" alt="Logo"/>
            </a></p>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../../np-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../../index.html">SciTools 0.9.0 documentation</a> &raquo;</li>
          <li><a href="../index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2012, H. P. Langtangen, J. Ring, ++.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.2.
    </div>
  </body>
</html>